package cn.dckeji.dcssm.common.config;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author kenny
 * @Title: Swagger2Config
 * @ProjectName dcssm
 * @Description: Swagger2的 配置类
 * @date 2019/2/21 15:50
 */
@EnableSwagger2
//@EnableWebMvc
@Configuration
//@ComponentScan(basePackages = {"cn.dckeji.dcssm.controller"})
public class Swagger2Config {

    @Value("${swagger.show}")
    private boolean swaggerShow;

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .enable(swaggerShow)
                .apiInfo(apiInfo())
                .select()
//                .apis(RequestHandlerSelectors.any())
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                .paths(PathSelectors.regex("/api.*"))
                .build();
    }

    //分组
//    @Bean("用户模块")
//    public Docket userApis() {
//        return new Docket(DocumentationType.SWAGGER_2)
//                .groupName("用户模块")
//                .select()
//                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
//                .paths(PathSelectors.regex("/user.*"))
//                .build()
//                .apiInfo(apiInfo())
//                .enable(true);
//    }
//
//    @Bean("客户模块")
//    public Docket customApis() {
//        return new Docket(DocumentationType.SWAGGER_2)
//                .groupName("客户模块")
//                .select()
//                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
//                .paths(PathSelectors.regex("/custom.*"))
//                .build()
//                .apiInfo(apiInfo())
//                .enable(true);
//    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("江苏点创科技SSM脚手架系统平台接口文档")
                .description("江苏点创科技SSM脚手架系统平台接口文档")
                .termsOfServiceUrl("http://dckeji.cn")
                .version("1.0")
                .build();
    }

}
